package com.shuzijun.leetcode.editor.cn;

import java.util.HashMap;

public class CheckPermutationLcci{
    public static void main(String[] args) {
         Solution solution = new CheckPermutationLcci().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public boolean CheckPermutation(String s1, String s2) {
        HashMap<Character, Integer> s1h = new HashMap<>();
        for (int i = 0; i < s1.length(); i++) {
            char c = s1.charAt(i);
            int count = 1;
            if (s1h.containsKey(c)){
                count += s1h.get(c);
            }
            s1h.put(c,count);
        }

        for (int i = 0; i < s2.length(); i++) {
            char c = s2.charAt(i);
            if (!s1h.containsKey(c)){
                return false;
            }
            Integer count = s1h.get(c);
            if (count == 0) return false;
            s1h.put(c,count-1);
        }

        for (int i = 0; i < s1.length(); i++) {
            char c = s1.charAt(i);
            if (s1h.get(c) != 0) return false;
        }

        return false;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}